package io.yizoo.business.controller;

import io.yizoo.business.entity.biz_crm_after_sales;
import io.yizoo.business.entity.biz_crm_customer;
import io.yizoo.business.entity.biz_hrm_ei_basic;
import io.elm.core.CoreController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.EnumSet;
import java.util.List;

@RestController
@RequestMapping("/business/crm/after_sales")
public class crm_after_salesController extends CoreController {

    @Override
    protected void Init() {
        PowerEntity = biz_crm_after_sales.class;
        PowerUse = EnumSet.of(Power.IDDelete, Power.IDAny, Power.IDGetSingle,Power.IDUpsert);
    }

    @PostMapping("/GetData")
    public Object GetData(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .From(biz_crm_after_sales.class,"t")
                        .Select("t.*,a.name as fwr_mc,ifnull(b.name,t.kh_name) as kh_name_mc")
                        .LeftJoin(biz_hrm_ei_basic.class,"a","a.emp_code=t.fwr")
                        .LeftJoin(biz_crm_customer.class,"b","b.id=t.kh_name")
                        .IsWhere("and (shqq like concat('%', #{name}, '%') or kh_name like concat('%', #{name}, '%')", "name")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

}

